
#include "stdafx.h"
#include "DatabaseLogging.h"
#include "Database.h"
#include "ADOAdapter.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

#import "msado15.dll" rename_namespace("") rename("EOF", "ADO_EOF") rename("BOF", "ADO_BOF")

const char preSql[] = "IF NOT EXISTS (select * from dbo.sysobjects where id = object_id(N'[Log]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "
                      "BEGIN "
                      "  CREATE TABLE [Log] ( "
	                    "    [Id] [int] IDENTITY (1, 1) NOT FOR REPLICATION  NOT NULL , "
	                    "    [Guid]  uniqueidentifier ROWGUIDCOL  NOT NULL , "
	                    "    [Timestamp] [datetime] NOT NULL , "
	                    "    [Severity] [int] NOT NULL , "
	                    "    [Description] [nvarchar] (1024) NULL , "
	                    "    [StackTrace] [text] NULL "
                      "  ) "
                      " "
                      "  ALTER TABLE [Log] WITH NOCHECK ADD "
	                    "    CONSTRAINT [PK_Log] PRIMARY KEY  CLUSTERED "
	                    "    ( "
		                  "      [Id] "
	                    "    ) " 
                      " "
                      "  ALTER TABLE [Log] WITH NOCHECK ADD "
	                    "    CONSTRAINT [DF_Log_Guid] DEFAULT (newid()) FOR [Guid], "
	                    "    CONSTRAINT [DF_Log_Time] DEFAULT (getdate()) FOR [Timestamp], "
	                    "    CONSTRAINT [DF_Log_Severity] DEFAULT (3) FOR [Severity] "
                      "END "
                      "GO";

bool initializeDatabase()
{
  CPoolFactory * factory = new CADOPoolFactory;
  CPool * pool = factory->getPool();
  CResource * res = pool->aquire();

#ifdef MSSQL


#endif

  pool->release(res);
  res = NULL;
  return false;
}

CDatabaseLogging::CDatabaseLogging()
{
  initializeDatabase();
}

void CDatabaseLogging::write(CEntry * entry)
{

}




